(function() {
  $(function() {
    var $dialog;
    $dialog = $("#user_edit_password");
    return $dialog.delegate("form", "submit", function(e) {
      var $error, $form, $success, old_password, password, password_confirmation;
      e.preventDefault();
      $form = $(e.currentTarget);
      $success = $(".alert-success", $form);
      $error = $(".alert-warning", $form);
      old_password = $("input.old_password", $form).val();
      password = $("input.password", $form).val();
      password_confirmation = $("input.password_confirmation", $form).val();
      if ($.isEmptyObject(password)) {
        $error.html("新密码为空！");
        $error.show();
        return;
      }
      if (!password_confirmation === password) {
        $error.html("新密码与确认密码不一致！");
        $error.show();
        return;
      }
      return $.ajax({
        url: $form.attr("action"),
        data: $form.serialize(),
        type: "put",
        dataType: "json",
        success: function(e) {
          $error.hide();
          $success.html("修改成功");
          $success.show();
          $dialog.modal("hide");
          return $form[0].reset();
        },
        error: function(e) {
          $success.hide();
          $error.html(JSON.parse(e.responseText).join(','));
          return $error.show();
        }
      });
    }).on("click", ".save", function() {
      return $("form", $dialog).submit();
    });
  });

}).call(this);
